//
//  CZNewFeatureCell.swift
//  weibo
//
//  Created by Mac on 16/5/17.
//  Copyright © 2016年 fengzhixiang. All rights reserved.
//

import UIKit

class CZNewFeatureCell: UICollectionViewCell {

    //根据cell显示的哪一页设置对应的图片
    var index:Int = 0 {
        //Int一旦改变就走这里
        didSet{
            // cell要显示的那一刻,collectionView就会来给cell设置index,让我们的cell知道要显示哪一页
            // 根据页码设置图片
            CZPrint(items: "第\(index)页将要显示")
            bkgImageView.image = UIImage(named: "new_feature_\(index+1)")

            //隐藏开始按钮
            startButton.hidden = true
        }

    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override init(frame: CGRect) {
        super.init(frame: frame)

        prepareUI()
    }


    func prepareUI(){
        //1.添加控件
        contentView.addSubview(bkgImageView)
        contentView.addSubview(startButton)

        //2.添加约束
        bkgImageView.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(self.contentView)
        }

        startButton.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.contentView)
            make.bottom.equalTo(self.contentView).offset(-160)
        }

    }

    ///定义一个给外部调用的开始按钮动画方法
    func startAnimation(){
        startButton.hidden = false
        // 在动画前设置transform.scale为0.看不到
        startButton.transform = CGAffineTransformMakeScale(0, 0)

        UIView.animateWithDuration(0.5, delay: 0.1, usingSpringWithDamping: 0.7, initialSpringVelocity: 7, options: UIViewAnimationOptions(rawValue: 0), animations: { () -> Void in
            //恢复到原来的大小
            self.startButton.transform = CGAffineTransformMakeScale(1, 1)
            }, completion: nil)
    }

    // MARK: -  按钮点击事件
    func startButtonClick(){



    }


    // MARK: - 懒加载
    ///背景imageView
    private lazy var bkgImageView: UIImageView = UIImageView(image: UIImage(named: "new_feature_1"))

    ///开始按钮
    private lazy var startButton: UIButton = {
        let button = UIButton()

        //设置文字
        button.setTitle("开始体验", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "new_feature_finish_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "new_feature_finish_button_highlighted"), forState: UIControlState.Highlighted)

        //隐藏按钮
        button.hidden = true

        return button
    }()


}







